﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AoCchatUI
{
    public delegate void UpdateTextDelegate(string pString); 

    public class TextBoxWriter : System.IO.TextWriter
    {
        RichTextBox _textBox;

        public TextBoxWriter(RichTextBox pTextBox)
        {
            _textBox = pTextBox;
        }


        public override void WriteLine(string value)
        {
            object[] x = { value };
            if (_textBox.InvokeRequired)
            {
                _textBox.Invoke(new UpdateTextDelegate(UpdateText), new object[] { value });
            }
            else
            {
                _textBox.Text += value + "\r\n";
            }

        }

        public override System.Text.Encoding Encoding
        {
            get
            {
                // TODO: Add TextBoxWriter.Encoding getter implementation
                return null;
            }
        }
        private void UpdateText(string pString)
        {
            _textBox.Text += pString + "\r\n";          
        }
    }
}
